<?php

namespace App\Http\Requests\Validators;

use Illuminate\Support\Facades\Validator;

class BaseValidator
{
    public function validate($input, $rules, $messages = [], $custom_attributes = [])
    {
        $validator = Validator::make($input, $rules, $messages, $custom_attributes);

        if ($validator->fails()) {
            foreach ($validator->errors()->messages() as $key => $error) {
                abort(422, $error[0]);
            }
        }
        return true;
    }

    static public function newInstance()
    {
        return (new static);
    }

    public function messages()
    {
        return [
            'required' => ':attribute 必填',
            'in' => ':attribute 必须在指定范围内',
            'numeric' => ':attribute 必须是数字',
            'string' => ':attribute 必须是字符串',
            'date_format' => ':attribute 需要符合日期格式',
            'max' => ':attribute 不得超过最大限制',
            'unique' => ':attribute 已经存在',
        ];
    }

    public function attributes()
    {
        return [
            'type' => '类型',
            'name' => '名称',
            'statis' => '状态',
            'ratio' => '抽成比例',
            'value' => '数值',
            'link' => '链接地址',
            'title' => '标题',
            'province_id' => '省份',
            'city_id' => '市级',
            'area_id' => '区级',
            'budget' => '预算',
            'introduction' => '说明',
            'negotiate' => '面议',
            'deadline' => '截止时间',
            'detail' => '详情',
            'pid' => '上级id',
            'alias' => '别名',
            'type_level' => '类型级别',
            'phone' => '手机号',
            'price' => '价格',
        ];
    }
}
